<template>
  <div class="app-container">
    <div class="content">
      <!-- <div class="header">
        <span class="hname">账号:</span
        ><el-input v-model="input" placeholder="请输入个人账号"></el-input>
        <el-button type="warning">查询</el-button>
      </div> -->
      <div class="logoBox">
        <img src="@/assets/images/logo.png" alt="" />
      </div>
      <div class="rightHeader">
        <div class="header">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="large"
            :inline="true"
            label-width="82px"
          >
            <el-form-item label="货主:" prop="hz">
              <el-input
                v-model="queryParams.hz"
                placeholder="请输入货主名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="商品名称:" prop="skuDescr1">
              <el-input
                v-model="queryParams.skuDescr1"
                placeholder="请输入商品名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="批号:" prop="lotAtt04">
              <el-input
                v-model="queryParams.lotAtt04"
                placeholder="请输入批号"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="库位:" prop="locationId">
              <el-input
                v-model="queryParams.locationId"
                placeholder="请输入库位"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="69码:" prop="alternateSku2">
              <el-input
                v-model="queryParams.alternateSku2"
                placeholder="请输入69码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="small"
                @click="handleQuery"
                >搜索</el-button
              >
              <el-button
                type="primary"
                icon="el-icon-refresh"
                size="small"
                @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div class="footer">
          <img src="@/assets/images/back.png" alt="" @click="goBack" />
          <span @click="goBack">退出</span>
        </div>
      </div>
      <!-- 810 -->
      <div class="wtable">
        <el-table
          :data="tableData"
          class="tableContent"
          height="700"
          v-loading="loading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.8)"
          ><el-table-column
            fixed
            prop="hz"
            label="货主"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column
            fixed
            prop="sku"
            label="商品代码"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="skuDescr1"
            label="商品名称"
            width="180"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="alternateSku3"
            label="规格"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="qtyAvailed"
            label="可用数量"
            width="180"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="alternateSku4"
            label="厂家"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="lotAtt04"
            label="批号"
            width="180"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="locationId"
            label="库位"
            width="150"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="dw" label="单位" width="180" align="center">
          </el-table-column>
          <el-table-column prop="zl" label="装量" width="150" align="center">
          </el-table-column>
          <el-table-column
            prop="qtyAllocated"
            label="预分配"
            width="180"
            align="center"
          >
          </el-table-column>
        </el-table>
        <div>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="handleQuery"
          />
        </div>
      </div>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="dialogVisible = false"
    >
      <span>未查询到数据</span>
    </el-dialog>
  </div>
</template>

<script>
import { getInventory } from "@/api/subSystem/continer";
export default {
  data() {
    return {
      // 弹窗隐藏
      dialogVisible: false,
      // 总条数
      total: 0,
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        skuDescr1: null,
        lotAtt04: null,
        locationId: null,
        alternateSku2: null,
        hz: null,
      },
      // queryRules: {
      //   skuDescr1: [
      //     { required: true, message: "请输入商品名称", trigger: "blur" },
      //     { min: 5, trigger: "blur" },
      //   ],
      //   lotAtt04: [
      //     { required: true, message: "请输入批号", trigger: "blur" },
      //     { min: 5, trigger: "blur" },
      //   ],
      //   locationId: [
      //     { required: true, message: "请输入库位", trigger: "blur" },
      //     { min: 5, trigger: "blur" },
      //   ],
      //   alternateSku2: [
      //     { required: true, message: "请输入69码", trigger: "blur" },
      //     { min: 5, trigger: "blur" },
      //   ],
      // },
      initialTableData: [], // 初始状态的表格数据
      tableData: [],
    };
  },
  methods: {
    resetQuery() {
      this.tableData = [...this.initialTableData];
      this.queryParams.skuDescr1 = "";
      this.queryParams.lotAtt04 = "";
      this.queryParams.locationId = "";
      this.queryParams.alternateSku2 = "";
      this.queryParams.hz = "";
    },
    goBack() {
      this.$router.push("/subSystem1");
    },
    handleQuery() {
      if (
        this.queryParams.skuDescr1 ||
        this.queryParams.lotAtt04 ||
        this.queryParams.locationId ||
        this.queryParams.alternateSku2 ||
        this.queryParams.hz
      ) {
        this.loading = true;
        getInventory(this.queryParams)
          .then((res) => {
            if (Array.isArray(res.rows) && res.rows.length > 0) {
              this.tableData = res.rows;
              this.total = res.total;
              this.loading = false;
            } else {
              this.tableData = res.rows;
              this.total = res.total;
              this.dialogVisible = true;
              this.loading = false;
            }
          })
          .catch((error) => {
            this.loading = false;
          });
      } else {
        this.$message.error("请先填写搜索条件");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 0 !important;
  width: 100%;
  height: 100%;
  background: url("../assets/images/hcbanner2.jpg") no-repeat;
  overflow: hidden;
  ::v-deep .el-form-item__label {
    color: #fff;
    font-size: 16px;
    font-weight: 400;
  }
  ::v-deep .el-input--small .el-input__inner {
    height: 40px;
  }
  ::v-deep .el-pagination__jump {
    color: #ffffff;
  }
  ::v-deep .el-pagination__total {
    color: #ffffff;
  }
  ::v-deep .el-pagination {
    margin-right: 78px;
  }
  .pagination-container {
    background: transparent;
    padding: 0px 20px !important;
    margin-top: 5px !important;
  }
  .content {
    height: 100%;
  }
  .logoBox {
    width: 200px;
    margin-left: 15px;
    img {
      width: 200%;
    }
  }
  .rightHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-left: 90px;
    margin-top: -15px;
    .footer {
      display: flex;
      align-items: center;
      cursor: pointer;
      margin-top: -35px;
      color: #ffffff5d;
      font-size: 18px;
      img {
        width: 30%;
      }
      span {
        display: block;
        margin-left: -40px;
        margin-top: 15px;
        font-size: 12px;
      }
    }
  }
  .hname {
    width: 40px;
  }
  .el-button--medium {
    margin-left: 10px;
    font-size: 18px;
  }
  .wtable {
    width: 100%;
    text-align: center;
  }
  .tableContent {
    margin: 0 auto;
    width: 96%;
    margin-top: 10px;
  }
  ::v-deep .el-form-item__label {
    color: #fff;
  }
  ::v-deep .el-input {
    width: 90%;
    font-size: 16px;
  }
  ::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
  }
  ::v-deep .el-input--suffix .el-input__inner {
    padding-right: 0px;
  }
  ::v-deep .el-pagination.is-background .btn-next:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination.is-background .btn-prev:disabled {
    color: #797a7b;
  }
  ::v-deep .el-pagination span:not([class*="suffix"]) {
    min-width: 56.5px;
  }
  ::v-deep .el-form--inline .el-form-item {
    margin-right: 0;
  }
  ::v-deep .el-button--small {
    padding: 12px 15px;
    font-size: 14px;
  }
}
</style>
